package com.bskj.common.utils;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;

public class WeixinApiUtils {
    private static final String JSSDK_SIGNATURE_URI = "/jssdk_signture";
    private static final String WECHAT_SMALL_GET_USERINFP_URL = "https://api.weixin.qq.com/sns/jscode2session";

    public static JSONObject jssdk_signture(String url, String accountId) throws Exception {
        String apiUrl = Global.getConfig("WX_API_PREFIX_URL") + JSSDK_SIGNATURE_URI;
        LogUtils.debug("apiUrl:" + apiUrl + ",url:" + url);
        Map<String, String> params = new HashMap<String, String>();
        params.put("url", url);
        params.put("accountId", accountId);
        String jsonStr = HttpClientUtils.postRequest(apiUrl, params);
        return JSONObject.parseObject(jsonStr);
    }
    
    public static JSONObject smallGetUserInfo(String code) throws Exception {
        Map<String, String> params = new HashMap<String, String>();
        params.put("appid", "wx0c6ddc854ee29b49");
        params.put("secret", "13f635adbfe9ed531941f0448c4f7826");
        params.put("js_code", code);
        params.put("grant_type", "authorization_code");
        String jsonStr = HttpClientUtils.postRequest(WECHAT_SMALL_GET_USERINFP_URL, params);
        return JSONObject.parseObject(jsonStr);
    }
}
